package com.llt.ai.config;

import com.alibaba.cloud.ai.advisor.RetrievalRerankAdvisor;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import com.alibaba.cloud.ai.dashscope.embedding.DashScopeEmbeddingModel;
import com.alibaba.cloud.ai.dashscope.rerank.DashScopeRerankModel;
import com.llt.ai.tools.ExamAiTool;
import com.llt.ai.tools.QuestionAiTool;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.PromptChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: llt
 * @Date: 2025/8/5 19:58
 */
@Configuration
public class ChatClientConfig {
    /**
     * 配置默认模型、系统提示词、记忆、RAG 重排序、工具等
     */
    @Bean
    public ChatClient chatClient(DashScopeChatModel model, PromptChatMemoryAdvisor promptChatMemoryAdvisor,
                                 ToolCallbackProvider toolCallbackProvider, RetrievalRerankAdvisor retrievalRerankAdvisor,
                                 @Qualifier("ojSystemPrompt") String ojSystemPrompt, QuestionAiTool questionAiTool,
                                 ExamAiTool examAiTool) {
        return ChatClient.builder(model)
                .defaultSystem(ojSystemPrompt)
                // 开启记忆与向量化并打印日志
                .defaultAdvisors(retrievalRerankAdvisor, promptChatMemoryAdvisor, new SimpleLoggerAdvisor())
                // 自己的工具
                .defaultTools(questionAiTool, examAiTool)
                // 外部的工具
                .defaultToolCallbacks(toolCallbackProvider)
                .build();
    }
}
